package com.itheima.demo01.Exception;

public class Demo03Throw {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        int ele = getElement(arr, -1);
    }

    public static int getElement(int[] arr, int index) {
        if (arr == null) {
            throw new NullPointerException("传递进来的数组为空!");
        }
        if(index<0||index>=arr.length){
            throw new ArrayIndexOutOfBoundsException("索引超出数组长度!");
        }
        int ele = arr[index];
        return ele;
    }
}
